<?php
include_once 'BaseS.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Util.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Regex.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/MemberM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Push.php';

class VerificationEmailS extends BaseS {
	
	public function __construct() {
		parent::__construct ();
		parent::setTarget ( $this );
	}
	
	public function checkEmail($account, $ps_e, $device_key){
		
		if( !Regex::isEmail($account, 300) ){
			return false;
		}
			
		if( !Regex::isAccount($ps_e, 1, 256) ){
			return false;
		}
			
		if( !Regex::isAccount($device_key, 1, 64) ){
			return false;
		}
		
		$dao = new MemberM();
		
		$result = $dao->updateVerification($account, $ps_e, $device_key);
		$push = new Push();
		
		if($result){
			$pushRet = $dao->getPushNo($account, $ps_e, $device_key);
			if($pushRet->m_type == 1){
				$push->android("EMAIL 註冊完成，感謝您支持寵物生命線 APP!", array($pushRet->push_no));
			}else if($pushRet->m_type == 2){
				$push->ios("EMAIL 註冊完成，感謝您支持寵物生命線 APP!", array($pushRet->push_no));
			}
			
		}
		return $result;
	}

}

if (isset($_POST["action"])) {
	$service = new VerificationEmailS ();
	$service->__call ( $_POST["action"], null );
}

	
?>